package org.example.wxTest;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2023/5/23 10:33
 * @apiNote https://mp.weixin.qq.com/s/T-3QGCgNL7nXfo_vvnM-FQ
 */

public class Test001 {
    public static void main(String[] args) {
        int[] old = new int[]{8, 4, 6, 7, 9, 3, 1, 5};
        int a = 1;
        int b = 3;
        int n = 3;
        int[] now = test(old, a, b, n);
        System.out.println(Arrays.toString(now));
    }


    private static int[] test(int[] old, int a, int b, int n) {
        int[] difNum = new int[old.length];
        int[] result = new int[old.length];

        difNum[0] = old[0];
        for (int i = 1; i < old.length; i++) {
            difNum[i] = old[i] - old[i - 1];
        }
        difNum[a] += n;
        difNum[b + 1] -= n;
        result[0] = difNum[0];
        for (int i = 1; i < difNum.length; i++) {
            for (int j = 0; j <= i; j++) {
                result[i] += difNum[j];
            }
        }
        return result;
    }
}
